package com.jiushi.xxljob.task;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@RequiredArgsConstructor
public class XxlJobTest {

    @XxlJob("demoTask")
    public ReturnT<String> xxlJobTest(String date) {
        log.info("---------xxlJobTest定时任务执行成功--------");
        return ReturnT.SUCCESS;
    }

    @XxlJob("showTime")
    public ReturnT<String> showTime(String date) {
        if (date == null) {
            log.warn("date 参数为空，请检查任务配置。");
        }
        // 获取当前时间
        LocalDateTime now = LocalDateTime.now();
        // 定义时间的格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化时间
        String formattedDateTime = now.format(formatter);
        // 输出时间
        log.info("当前时间：{}", formattedDateTime);
        log.info("data：{}", date);
        return ReturnT.SUCCESS;
    }

}
